
** set path
// gl path ""

** open log
cap log close
log using "$path/table_a2.log", replace

use "$path/foreclosures_analysis.dta", clear

// lagged dv setup
replace lag_pres = lag_pres * 100

// run the lagged dv on our sample from table 1
bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs lag_pres foreclosure_rate foreclosure_inc [aw=pop_y], a(sy) cluster(fips)
local b1 = _b[lag_pres]
local se1 = _se[lag_pres]
local b1_2 = _b[foreclosure_rate]
local se1_2 = _se[foreclosure_rate]
local bint1 = _b[foreclosure_inc]
local seint1 = _se[foreclosure_inc]
local n1 = e(N)
local nclust1 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs lag_pres foreclosure_rate foreclosure_inc [aw=pop_y], a(popyear) cluster(fips)
local b2 = _b[lag_pres]
local se2 = _se[lag_pres]
local b2_2 = _b[foreclosure_rate]
local se2_2 = _se[foreclosure_rate]
local bint2 = _b[foreclosure_inc]
local seint2 = _se[foreclosure_inc]
local n2 = e(N)
local nclust2 = e(N_clust)

log close

quietly {
	cap log close
	set linesize 255
	log using "$path/foreclosure_main_lagged_dv.tex", text replace
	
	noisily dis "\begin{table}[h]"
	noisily dis "\centering"
	noisily dis "\caption{\textbf{Effects of Housing Foreclosures on Presidential Elections, Lagged Dependent Variable Approach, 2004--2016.}"
	noisily dis "\label{tab:main_lagged_dv}}"
	noisily dis "\begin{tabular}{lcc}"
	noisily dis "\toprule \toprule"
	noisily dis " & \multicolumn{2}{c}{Dem Vote Pct (0-100)}\\"
	noisily dis " & (1) & (2)   \\"
	noisily dis "\midrule"
	noisily dis "Dem Pres Vote Pct (t-1) & " %4.2f `b1' " & " %4.2f `b2'  "\\"
	noisily dis " & (" %4.2f `se1' ") & (" %4.2f `se2' ")  \smallskip\\"
	noisily dis "Foreclosures Per 1,000 People & " %4.2f `b1_2' " & " %4.2f `b2_2'  "\\"
	noisily dis " & (" %4.2f `se1_2' ") & (" %4.2f `se2_2' ") \smallskip\\"
	noisily dis "Foreclosures $ \times $ Inc Party &  " %4.2f `bint1' " & " %4.2f `bint2'  "\\"
	noisily dis " & (" %4.2f `seint1' ") & (" %4.2f `seint2' ")  \medskip \\"

	noisily dis " N & " %4.0fc `n1' " & " %4.0fc `n2'  " \\ "
	noisily dis " \# Counties & "  %4.0fc `nclust1' " & " %4.0fc `nclust2'  " \\ "
	noisily dis "State-Year Fixed Effects & Y & N  \\"
	noisily dis "Pop Decile-Year Fixed Effects & N & Y \\"
	noisily dis " Population Weights & Y & Y  \\"
	noisily dis "\bottomrule \bottomrule"
	noisily dis "\multicolumn{3}{p{.55\textwidth}}{\footnotesize Standard errors generated from 1,000 iterations of a county-level block bootstrap procedure. "
	noisily dis "Inc Party is 1 for Dem, -1 for Rep.  Main effect for Inc Party is absorbed by fixed effects.}"
	noisily dis "\end{tabular}"
	noisily dis "\end{table}"
	
	log off
	
}
